/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.proyecto;

import com.proyecto.datos.EntityConsultaIntro;
import com.proyecto.datos.EntityHorario;
import com.proyecto.modelado.DetalleAlumno;
import com.proyecto.modelado.Horario;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Point;
import java.util.ArrayList;
import javax.swing.JDesktopPane;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author mario
 */
public class frmMantenimiento_Horario extends javax.swing.JInternalFrame {

    Horario hora;
    ArrayList arryTable;

    public void PopularTable() {
        DefaultTableModel tabla;
        Object[] fila = new Object[2];

        try {
            String[] columnName = {"ID", "Horario"};
            tabla = new DefaultTableModel(null, columnName);
            //populamos el arraylist de la tabla
            arryTable = new ArrayList();
            hora = new Horario();
            EntityHorario entHora = new EntityHorario();
            arryTable = hora.MostrarCatalagoHorarios();
            if (arryTable != null) {
                for (int i = 0; i < arryTable.size(); i++) {
                    entHora = (EntityHorario) arryTable.get(i);
                    fila[0] = entHora.getId_horario();
                    fila[1] = entHora.getHorario();
                    tabla.addRow(fila);
                }
                this.jtbleHorarios.setModel(tabla);
            } else {
                JOptionPane.showMessageDialog(rootPane, "No se recuperaron datos de la base de datos", "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(rootPane, ex.toString());
        }
    }

    public frmMantenimiento_Horario() {
        initComponents();
        this.setTitle("Nuevo horario");
        PopularTable();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jbtnAgregar = new javax.swing.JButton();
        jtbnCancelar = new javax.swing.JButton();
        jcmbDia = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jcmbHorario = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtbleHorarios = new javax.swing.JTable();

        setClosable(true);

        jLabel1.setText("Dia:");

        jbtnAgregar.setIcon(new javax.swing.ImageIcon("/home/mario/Dropbox/Sistema de laboratorio/Imagenes/agregar.jpg")); // NOI18N
        jbtnAgregar.setText("Agregar");
        jbtnAgregar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jbtnAgregarMouseClicked(evt);
            }
        });

        jtbnCancelar.setText("Cancelar");
        jtbnCancelar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jtbnCancelarMouseClicked(evt);
            }
        });

        jcmbDia.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "[SELECCIONE]", "Lunes y Miercoles", "Martes y Jueves", "Viernes", "Sabado", "Domingo" }));

        jLabel2.setText("Horario:");

        jcmbHorario.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "[SELECCIONE]", "6:20 am a 8:00 am", "8:10 am a 9:40 am", "10:00 am a 11:40 am", "4:50 pm a 6:30 pm", "6:30 pm a 8:100 pm", "______________________", "6:20 am a 9:40 am", "10:00 am a 1:00 pm", "4:50 pm a 8:10 pm" }));

        jtbleHorarios.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(jtbleHorarios);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jbtnAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jtbnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap(46, Short.MAX_VALUE)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 572, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(72, 72, 72)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addGap(32, 32, 32)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jcmbHorario, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jcmbDia, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(27, 27, 27)))
                .addGap(55, 55, 55))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jcmbDia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jcmbHorario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(45, 45, 45)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 42, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbtnAgregar)
                    .addComponent(jtbnCancelar))
                .addGap(25, 25, 25))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jtbnCancelarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jtbnCancelarMouseClicked
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jtbnCancelarMouseClicked

    private void jbtnAgregarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbtnAgregarMouseClicked
        // TODO add your handling code here:
        String dia = (String) this.jcmbDia.getSelectedItem();
        String horario = (String) this.jcmbHorario.getSelectedItem();

        hora = new Horario();
        String msj = hora.InsertarHorario(dia, horario);
        JOptionPane.showMessageDialog(rootPane, msj, "Nuevo horario", JOptionPane.INFORMATION_MESSAGE);
        PopularTable();
        

    }//GEN-LAST:event_jbtnAgregarMouseClicked
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbtnAgregar;
    private javax.swing.JComboBox jcmbDia;
    private javax.swing.JComboBox jcmbHorario;
    private javax.swing.JTable jtbleHorarios;
    private javax.swing.JButton jtbnCancelar;
    // End of variables declaration//GEN-END:variables
}
